<include file="Public/header" />
<title>我的桌面</title>
</head>
<body>
<div class="page-container">
    <div class="text-c">
        日期范围：
        <input type="text" onfocus="WdatePicker({maxDate:'#F{$dp.$D(\'logmax\')||\'%y-%M-%d\'}'})" id="logmin" name="start_time" value="<{$Think.get.start_time}>" class="input-text Wdate" style="width:120px;">
        -
        <input type="text" onfocus="WdatePicker({minDate:'#F{$dp.$D(\'logmin\')}',maxDate:'%y-%M-%d'})" id="logmax" name="end_time" value="<{$Think.get.end_time}>" class="input-text Wdate" style="width:120px;">
        <input type="text" name="name" id="name" value="<{$Think.get.name}>" placeholder="账册名称" style="width:250px" class="input-text">
        <button id="search" class="btn btn-success" type="submit"><i class="Hui-iconfont"></i> 搜索</button>
    </div>
    <div class="cl pd-5 bg-1 bk-gray mt-20">
        <span class="l">
            <a href="javascript:;" onclick="delAll()" class="btn btn-danger radius"><i class="Hui-iconfont"></i> 批量删除</a>
            <a class="btn btn-primary radius" data-title="添加账册" _href="article-add.html" onclick="add()" href="javascript:;"><i class="Hui-iconfont"></i> 添加账册</a>
			<a class="btn btn-primary radius" data-title="账册同步" onclick="syn_book()" href="javascript:;">账册同步</a>
        </span>
        <span class="r">共有数据：<strong><{$count}></strong> 条</span>
    </div>
    <div class="mt-20">
        <div id="DataTables_Table_0_wrapper" class="dataTables_wrapper no-footer">
            <div class="dataTables_length" id="DataTables_Table_0_length"><label>
                显示 <select tabindex="<{$Think.get.page_count}>" name="page_count" aria-controls="DataTables_Table_0" class="select">
                <option value="15">15</option><option value="25">25</option><option value="50">50</option>
                <option value="100">100</option></select> 条</label></div>
            <table class="table table-border table-bordered table-bg table-hover table-sort dataTable no-footer" id="DataTables_Table_0" role="grid" aria-describedby="DataTables_Table_0_info">
            <thead>
            <tr class="text-c" role="row">
                <th width="25" rowspan="1" colspan="1"><input type="checkbox" name="" value=""></th>
                <th width="80" class="sorting_desc" tabindex="id" aria-controls="DataTables_Table_0">ID</th>
                <th class="sorting" tabindex="name" rowspan="1" colspan="1" aria-label="标题: 升序排列" style="width: 187px;">名称</th>
                <th width="100">账册编号</th>
                <th width="80" class="sorting" tabindex='type'>账册类型</th>
				<th width="100">商家编号</th>
                <th width="60">状态</th>
                <th width="60">操作人</th>
                <th width="100">添加时间</th>
                <th width="100">操作</th>
            </tr>
            </thead>
            <tbody>
            <foreach name="list" item="data">
            <tr class="text-c odd" role="row">
                <td><input type="checkbox" value="<{$data.id}>" name=""></td>
                <td class="sorting_1"><{$data.id}></td>
                <td class="text-l"><span style="cursor:pointer" class="text-primary"><{$data.name}></span></td>
                <td><{$data.book_no}></td>
                <td>
                    <eq name="data.type" value="1">
                        一般账册
                        <else/>
                         跨境账册
                    </eq>
                </td>
				<td><{$data.merchant_code}></td>
                <td>
                    <eq name="data.examined" value="2">已审核
                        <else/>
                        <eq name="data.examined" value="1">等待审核
                            <else/>未推送
                        </eq>
                    </eq>
                </td>
                <td><{$data.operator}></td>
                <td><{$data.created_at|substr=0,-3}></td>
                <td class="f-14 td-manage">
                    <a style="text-decoration:none" class="ml-5" onclick="edit('<{$data.id}>')" href="javascript:;" title="编辑"><i class="Hui-iconfont"></i></a>
                    <a style="text-decoration:none" class="ml-5" onclick="del('<{$data.id}>')" href="javascript:;" title="删除"><i class="Hui-iconfont"></i></a>
                    <eq name="data.examined" value="0">
                        <a style="text-decoration:none" class="ml-5" onclick="pushs('<{$data.id}>')" href="javascript:;" title="推送"><i class="Hui-iconfont Hui-iconfont-arrow1-top"></i>推送</a>
                    </eq>
                </td>
            </tr>
            </foreach>
            </tbody>
        </table>
            <div class="page">
                <{$page}>
            </div>
    </div>
</div>
<include file="Public/footer" />
<include file="Public/footer_js" />
<script>
	function syn_book(){
		url="<{:U('syn_book')}>";
		merchant_code="<{:C('base_config.merchant_code')}>";//货主编码
        var index=layer.confirm('同步将覆盖现在的数据，确定同步吗?',function(){
			$.ajax({
				type:'post',
				data:{merchant_code:merchant_code},
				url:url,
				success:function(data){
					if(data.status==1){	
						layer.msg(data.message,function(){
							window.location.reload();
						});
					}else{
						layer.msg(data.message);
					}
					return false;
				}
			})
		});
    }
    function add(){
        var index=layer.open({
            type: 2,
            title: '账册添加',
            shadeClose: true,
            shade: 0.5,
            offset:['180px'],
            area: ['520px', '335px'],
            content: '__MODULE__/book/add' //iframe的url
        });
    }
    function edit(id){
        var index=layer.open({
            type: 2,
            title: '账册修改',
            shadeClose: true,
            shade: 0.5,
            offset:['180px'],
            area: ['520px', '335px'],
            content: '__MODULE__/Book/edit/id/'+id+"/"+Math.random() //iframe的url
        });
    }
    function delAll(){
        var all_ipt=$("#DataTables_Table_0_wrapper input[type=checkbox]:checked");
        var group_id='';
        for(var i=0;i<all_ipt.length;i++){
            if(all_ipt.eq(i).val()!==''){
                group_id+='@'+all_ipt.eq(i).val();
            }
        }
        if(group_id.substring(1)==''){
            layer.msg('请勾选要删除的信息');
            return false;
        }
        del(group_id.substring(1));
    }
    function del(id){
        $.get('__MODULE__/Book/del',{
            id:id,
        },function (msg){
            layer.msg(msg.data);
            if(msg.flag==1){
                setTimeout(function (){
                    location.reload();
                },800);
            }
        },'json');
    }
    function pushs(id){
        var index=layer.open({
            type: 1,
            title: '推送仓库选择',
            shadeClose: true,
            shade: 0.5,
            offset:['100px'],
            area: ['320px', '180px'],
            content: "<div id='warehouse' style='padding: 12px;'></div>",
            btn:['确定','取消'],
            success:function (){
                $.get('__MODULE__/Book/getWarehouse',function (msg){
                    if(msg.flag==0){
                        layer.msg('没有仓库信息');
                    }else{
                        var data=msg.data;
                        for(var m in data){
                            $("#warehouse").append("<label><input type='radio' name='wares' value='"+m+"' /> "+data[m]+"</label>");
                        }
                    }
                },'json');
            },
            yes:function (){
                $.get('__MODULE__/book/push',{
                    id:id,
                    warehouse_id:$("#warehouse input:checked").val(),
                },function (msg){
                    layer.msg(msg.data);
                    if(msg.flag==1){
                        setTimeout(function (){
                            location.reload();
                        },800);
                    }
                },'json');
            }
        });
    }
    $("select[name=page_count]").on('change',function (){
        search();
    });
    $("#search").on('click',function (){
        search();
    });
    function search(_this){
        var page_count=$("select[name=page_count]").val();
        var start_time=$("input[name=start_time]").val();
        var end_time=$("input[name=end_time]").val();
        var name=$("input[name=name]").val();
        var category=$("select[name=category]").val();
        var sort,dec;
        if(_this){
            if(_this.attr('class')=='sorting_desc'){
                sort=_this.attr('tabindex');
                dec='asc';
            }
            if(_this.attr('class')=='sorting_asc'){
                sort=_this.attr('tabindex');
                dec='desc';
            }
            if(_this.attr('class')=='sorting'){
                sort=_this.attr('tabindex');
                dec='asc';
            }
        }else{
            sort='';
            dec='';
        }
        location.href="__ACTION__?name="+name+"&page_count="+page_count+"&start_time="+start_time+"&end_time="+end_time+"&sort="+sort+"&dec="+dec;
    }

    (function(){
        if($("select[name=page_count]").attr('tabindex')==''){
            var  page=15;
        }else{
            var  page=$("select[name=page_count]").attr('tabindex');
        }
        $("select[name=page_count]").prop('value',page);
        $(".sorting,.sorting_desc,.sorting_asc").click(function (){
            search($(this));
        });
        for(var i=0;i<$(".sorting,.sorting_desc,.sorting_asc").length;i++){
            if('<{$Think.get.sort}>'!=''){
                if($(".sorting,.sorting_desc,.sorting_asc").eq(i).attr('tabindex')=='<{$Think.get.sort}>'){
                    $(".sorting,.sorting_desc,.sorting_asc").attr('class','sorting');
                    $(".sorting,.sorting_desc,.sorting_asc").eq(i).attr('class','sorting_<{$Think.get.dec}>');
                }
            }
        }
    })();
</script>
</body>
</html>